package cn.kgc.tangcco.tcbd1011.no13.vehicletype.action;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.kgc.tangcco.tcbd1011.no13.base.action.BaseServlet;
import cn.kgc.tangcco.tcbd1011.no13.base.properties.factory.PropertiesFactory;
import cn.kgc.tangcco.tcbd1011.no13.base.util.MyBeanUtils;
import cn.kgc.tangcco.tcbd1011.no13.base.util.Utils;
import cn.kgc.tangcco.tcbd1011.no13.vehicletype.entity.VehicleType;
import cn.kgc.tangcco.tcbd1011.no13.vehicletype.service.VehicleTypeService;
import cn.kgc.tangcco.tcbd1011.no13.vehicletype.vo.VehicleTypeVo;
@WebServlet(name="VehicleTypeServlet",urlPatterns="/vehicleType.action")
public class VehicleTypeServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	private static final String SUCCESS = "vehicleType.action?methodName=doListVehicleType";
	private VehicleTypeService vts;
	public VehicleTypeServlet() {
		vts = (VehicleTypeService) PropertiesFactory.getInstance(Utils.VEHICLETYPEService);
	}
	//跳转listVehicleType界面，并展示信息
	public String doListVehicleType(HttpServletRequest request, HttpServletResponse response) {
		String forward = "vehicletype/listVehicleType";
		VehicleTypeVo vehicleType = new VehicleTypeVo();
		request.setAttribute("vlist", vts.queryAllVehicleType(vehicleType));
		return forward;
	}
	//跳转detailVehicleType界面，展示一条信息
	public String doDetailVehicleType(HttpServletRequest request, HttpServletResponse response) {
		String forward = "vehicletype/detailVehicleType";
		request.setAttribute("vehicleType", vts.detailVehicleType(Utils.parseInt(request.getParameter("vehicleTypeId"))));
		return forward;
	}
	//去新增页面
	public String toAddVehicleType(HttpServletRequest request, HttpServletResponse response) {
		String forward = "vehicleType/addVehicleType";
		return forward;
	}
	//执行新增语法
	public String doAddVehicleType(HttpServletRequest request, HttpServletResponse response) {
		String forward = SUCCESS;
		int add = vts.addVehicleType(MyBeanUtils.populate(VehicleType.class, request.getParameterMap()));
		if(add>0) {
			request.setAttribute("add", add);
			return forward+"&add="+add;
		}
		return forward;
	}
	//去修改界面
	public String toUpdateVehicleType(HttpServletRequest request, HttpServletResponse response) {
		String forward = "vehicleType/updateVehicleType";
		request.setAttribute("vehicleType", vts.detailVehicleType(Utils.parseInt(request.getParameter("vehicleTypeId"))));
		return forward;
	}
	//执行修改操作
	public String doUpdateVehicleType(HttpServletRequest request, HttpServletResponse response) {
		String forward = SUCCESS;
		int update = vts.updateVehicleType(MyBeanUtils.populate(VehicleType.class, request.getParameterMap()));
		if(update>0) {
			request.setAttribute("update", update);
			return forward+"&update="+update;
		}
		return forward;
	}
	//删除一条信息
	public String doDeleteVehicleType(HttpServletRequest request, HttpServletResponse response) {
		String forward = SUCCESS;
		int delete = vts.deleteVehicleType(Utils.parseInt(request.getParameter("vehicleTypeId")));
		if(delete>0) {
			request.setAttribute("delete", delete);
			return forward+"&delete="+delete;
		}
		return forward;
	}
}
